<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/default/easyui.css" >
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

</head>
<script type="text/javascript">
	function query(){
		var name = $("#name").val();
		$("#dg").datagrid('load',{
			method:'query',
			name:name
		});
	}
	function clear(){
		$("#name").val("");
		query();
	}
	function del(){
		var rows = $("#dg").datagrid("getSelections");
		if(rows.length <=0){
			$.messager.alert('提示','请先选择要删除的数据！');
			return;
		}
		var idss = new Array();
		//var ids = [];
		for(var i=0;i < rows.length;i++){
			idss.push(rows[i].id);
		}
		var ids = idss.join(",");
		$.messager.confirm('系统提示',"你确定要删除这<font color='red'>"+rows.length+"</font>条数据吗？",function(r){
			if(r){
				$.post('gradeSer',{
					method:'delete',
					ids : ids
				},function(result){
					if(result.success){
						$.messager.alert('提示','成功删除'+result.num+'条数据！');
						$("#dg").datagrid("reload");
					}else{
						$.messager.alert('提示','删除失败！');
						$("#dg").datagrid('clearSelections');
					}
				},'json');
			}
		});
	}
	function add(){
		$("#dlg").dialog("open").dialog("setTitle","新增班级");
	}
	function edit(){
		var rows = $("#dg").datagrid("getSelections");
		if(rows.length < 1){
			$.messager.alert('提示','请先选择要编辑的一条记录!');
			return;
		}
		$("#dlg").dialog("open").dialog("setTitle","编辑班级");
		$("#fm").form("load",rows[0]);
	}
	function save(){
		$("#fm").form("submit",{
			url:'gradeSer?method=save',
			onSubmit:function(){
				var r = $(this).form("validate");
				if(!r){
					$.messager.alert('提示','表单验证失败！');
					return false;
				}
				return true;
			},
			success:function(result){
				eval("r="+result);
				$.messager.alert('提示',r.msg);
				reset();
				$("#dlg").dialog("close");
				$("#dg").datagrid('reload');
			},
			failure:function(result){
				
			}
		})
	}
	
	function cancel(){
		reset();
		$("#dlg").dialog("close");
	}
	function reset(){
		$("#id").val("");
		$("#n").val("");
		$("#descc").val("");
	}
</script>
<body>
<table  class="easyui-datagrid" id="dg" title="班级管理" toolbar="#tb" url="gradeSer?method=list" rownumbers="true" pagination="true" fit="true" style="width:1080px;">
	<thead>
		<tr>
			<th field="cb" checkBox="true"></th>
			<th field="id" hidden="true">id</th>
			<th field="name" width="500px;" align="center">班级名称</th>
			<th field="descc" width="500px;" align="center">班级描述</th>
		</tr>
	</thead>
</table>
<div id="tb">
	<div>
		<a class="easyui-linkbutton" iconCls="icon-add" onclick="javascript:add()" plain="true">新增</a>
		<a class="easyui-linkbutton" iconCls="icon-edit"  onclick="javascript:edit()" plain="true">编辑</a>
		<a class="easyui-linkbutton" iconCls="icon-remove" onclick="javascript:del()" plain="true">删除</a>
	</div>
	<div style="margin-left:400px;">
		班级名称&nbsp;
		<input type="text" name="name" id="name"/>
		<a class="easyui-linkbutton" iconCls="icon-search" href="javascript:query()">查询</a>
		<a class="easyui-linkbutton" iconCls="icon-back" href="javascript:clear()">清空</a>
	</div>
</div>
<div class="easyui-dialog" id="dlg" buttons="#dlgbtn" closed="true" style="width:330px;height:230px;">
	<form id="fm" method="post" style="padding:40px 0 0 50px">
		<table>
			<tr>
				<td><input type="text" name="id" id="id" hidden="true"/>
			</tr>
			<tr>
				<td>班级名称&nbsp;&nbsp;</td>
				<td><input type="text" name="name" id="n"/></td>
			</tr>
			<tr>
				<td>班级描述&nbsp;&nbsp;</td>
				<td><input type="text" name="descc" id="descc"/></td>
			</tr>
		</table>
	</form>
</div>
<div id="dlgbtn" style="padding-right:100px;">
	<a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:save()">保存</a>
	<a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:cancel()">关闭</a>
</div>
</body>
</html>